<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Class OrderCustoms
 * @property Order order
 * @package App\Models
 */
class OrderCustoms extends Model
{
    protected $table = 'order_customs';

    protected $fillable = ['order_id','last_time'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function order(){
        return $this->belongsTo(Order::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @author luffyzhao@vip.126.com
     */
    public function logs(){
        return $this->hasMany(OrderCustomsLog::class)->orderByDesc('last_time');
    }

    protected static function boot()
    {
        static::addGlobalScope('orderBy', function (Builder $query){
            $query->orderByDesc('id');
        });
        parent::boot();
    }


}
